package com.china.fragment;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.support.design.widget.TabLayout;

import com.china.base.BaseFragment;
import com.china.osourcechina.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/5/7.
 */
public class Movefragment extends BaseFragment{

    private TabLayout tl_move_table;
    private ViewPager vp_move_viewpager;
    private List<Fragment> mFragments;
    private List<String> mFragmentTitles;
    private Adapter adapter;

    @Override
    protected int getLoadViewId() {
        return R.layout.fragment_move;
    }

    @Override
    protected void initView(View view) {
        tl_move_table = (TabLayout)view.findViewById(R.id.tl_move_table);
        vp_move_viewpager = (ViewPager)view.findViewById(R.id.vp_move_viewpager);
        setupViewPager(vp_move_viewpager);
        tl_move_table.setupWithViewPager(vp_move_viewpager);
    }

    private void setupViewPager(ViewPager viewPager) {
        mFragments = new ArrayList<>();
        mFragmentTitles = new ArrayList<>();
        for(int i = 0;i<3;i++){
            Bundle data = new Bundle();
            if(i==0){
                data.putInt("uid", 0);
            }else if(i==1){
                data.putInt("uid",-1);
            }else if(i==2){
                data.putInt("uid",1);
            }
            MoveFailsfragment mf = new MoveFailsfragment();
            mf.setArguments(data);
            mFragments.add(mf);
        }
//        mFragments.add(new MineMoveFragment());
        mFragmentTitles.add("最新动弹");
        mFragmentTitles.add("热门动弹");
        mFragmentTitles.add("我的动弹");
        adapter = new Adapter(getChildFragmentManager());
        viewPager.setAdapter(adapter);
    }

    @Override
    protected void initData() {

    }

    class Adapter extends FragmentPagerAdapter {
        public Adapter(FragmentManager fm) {
            super(fm);
        }
        @Override
        public Fragment getItem(int position) {
            return mFragments.get(position);
        }
        @Override
        public int getCount() {
            return mFragments.size();
        }
        @Override
        public CharSequence getPageTitle(int position) {
            return mFragmentTitles.get(position);
        }
    }
}
